package com.ruoyi.web.controller.system;

import cn.hutool.core.date.DateUtil;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysTaskCycle;
import com.ruoyi.common.pojo.*;
import com.ruoyi.system.service.SysTaskCycleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Author: zhangzhe
 * @Date: 2023/9/6
 */

@Api(tags = "1.2常规任务计划")
@RestController
@RequestMapping("/system/taskplanconfig")
public class SysTaskCycleController {

    @Resource
    SysTaskCycleService service;

    @ApiOperation("1.2.1添加常规周期任务计划配置")
    @ApiOperationSupport(order = 1)
    @PostMapping("/addTaskPlanConfig")
    public AjaxResult add(@RequestBody AddTaskPlanConfigReq param) {
        SysTaskCycle sysTaskCycle = new SysTaskCycle();
        sysTaskCycle.setStatus(1);
        sysTaskCycle.setCreateTime(DateUtil.date());
        sysTaskCycle.setCycleId(param.getCycleId());
        sysTaskCycle.setFrequency(param.getFrequency());
        sysTaskCycle.setPostId(param.getPostId());
        return AjaxResult.success(service.save(sysTaskCycle));
    }

    @ApiOperation("1.2.2删除常规周期任务计划配置")
    @ApiOperationSupport(order = 2)
    @PostMapping("/deleteTaskPlanConfig")
    public AjaxResult getList(@RequestBody DeleteTaskPlanConfigReq param) {
        return AjaxResult.success(service.removeById(param.getId()));
    }

    @ApiOperation("1.2.3编辑常规周期任务计划配置")
    @ApiOperationSupport(order = 3)
    @PostMapping("/editTaskPlanConfig")
    public AjaxResult edit(@RequestBody EditTaskPlanConfigReq param) {
        SysTaskCycle sysTaskCycle = new SysTaskCycle();
        sysTaskCycle.setId(param.getId());
        sysTaskCycle.setCycleId(param.getCycleId());
        sysTaskCycle.setFrequency(param.getFrequency());
        sysTaskCycle.setPostId(param.getPostId());
        return AjaxResult.success(service.updateById(sysTaskCycle));
    }

    @ApiOperation("1.2.4根据职位判断计划配置是否存在")
    @ApiOperationSupport(order = 4)
    @PostMapping("/checkTaskPlanConfigByPostId")
    public AjaxResult exist(@RequestBody CheckTaskPlanConfigByPostIdReq param) {
        return service.exist(param.getPostId());
    }

    @ApiOperation("1.2.5获取常规周期")
    @GetMapping("/getCycle")
    @ApiOperationSupport(order = 5)
    public AjaxResult getCycleList() {
        return service.getCycleList();
    }

    @ApiOperation("1.2.6查询常规周期任务计划配置列表")
    @ApiOperationSupport(order = 6)
    @GetMapping("/searchTaskPlanConfig")
    public AjaxResult getList() {
        return service.getList();
    }

    @ApiOperation("1.2.7查询常规周期任务计划配置详情")
    @ApiOperationSupport(order = 7)
    @GetMapping("/getTaskPlanConfig")
    public AjaxResult getInfo(Long id) {
        return service.getInfo(id);
    }

    @ApiOperation("1.2.8切换常规周期任务计划配置开关")
    @ApiOperationSupport(order = 8)
    @PostMapping("/switchTaskPlanConfig")
    public AjaxResult switchTaskCycle(@RequestBody SwitchTaskCycle param) {
        return service.switchTaskCycle(param);
    }




}
